<template>
  <div>
    <qrcode-vue v-if="loginType===1" :value="qrcodeUrl" :size="200" level="H" />
    <phoneLogin v-if="loginType===2"></phoneLogin>
  </div>

</template>

<script setup lang="ts">
  import { onMounted, ref } from 'vue';
  import { MessagePlugin } from 'tdesign-vue-next';

  import QrcodeVue from 'qrcode.vue';
  import phoneLogin from './phoneLogin.vue';
  import { useWebsocketStore } from '@/store';
  import { getWxLoginQrcode } from '@/api/permission';

  const qrcodeUrl = ref('https://rscode.cn');
  const wsStore = useWebsocketStore();
  const loginType = ref(1)
  const changeLoginType = (type : number) => {
    loginType.value = type
  }
  //获取微信登录二维码并显示
  const getQrCodeInfo = () => {
    let inviteCode = localStorage.getItem('inviteCode')
    if (inviteCode === null) {
      inviteCode = ''
    }
    console.log('wsStore.websocketId='+wsStore.websocketId)
    getWxLoginQrcode({ websocketId: wsStore.websocketId, inviteCode: inviteCode })
      .then((ret) => {
        console.log('ret' + JSON.stringify(ret));
        qrcodeUrl.value = ret.url;
      })
      .catch((e) => {
        console.log('e' + JSON.stringify(e));
        MessagePlugin.error(e.msg);
      });
  };

onMounted(()=>{
  getQrCodeInfo();
})

</script>

<style></style>
